#include <coroutine>
#include <iostream>

struct Promise {
    std::coroutine_handle<Promise> get_return_object() { return std::coroutine_handle<Promise>::from_promise(*this); } 
    std::suspend_always initial_suspend() noexcept { return {}; }
    std::suspend_always final_suspend() noexcept { return {}; }
    void return_void() {}
    auto yield_value(int value) {
        mValue = value;
        return std::suspend_never();
    }
    void unhandled_exception() {}

    int mValue;
};

struct Task {
    using promise_type = Promise;

    Task(std::coroutine_handle<Promise> coroutine) : mCoroutine(coroutine) {

    }

    std::coroutine_handle<Promise> mCoroutine;
};

Task hello() {
    std::cout << "hello 45" << std::endl;
    co_yield 45;
    std::cout << "hello 42" << std::endl;
    co_yield 42;
    std::cout << "结束了" << std::endl;
    co_return;
}

int main() {
    auto t = hello();
    while (!t.mCoroutine.done()) {
        t.mCoroutine.resume();
        std::cout << t.mCoroutine.promise().mValue << std::endl;
    }
    return 0;
}